package com.awesome.videodemo.localvideo;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.widget.ImageView;

import com.awesome.common.base.mvp.BaseActivity;
import com.awesome.common.constant.Constant;
import com.awesome.videodemo.R;
import com.awesome.videodemo.util.Utils;
import com.awesome.videodemo.util.VideoUtil;

/**
 * Author: zhangjingfang
 * Email:zhangjingfang@jeejio.com
 * Date: 2022/7/7 15:57
 * Description: 本地视频
 */
public class LocalVideoActivity extends BaseActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_local_video);
        ImageView imageView1 = findViewById(R.id.iv1);
        ImageView imageView2 = findViewById(R.id.iv2);
        ImageView imageView3 = findViewById(R.id.iv3);

        if (!hasPermission(Constant.WRITE_EXTERNAL_PERMISSION)) {
            requestPermission(Constant.WRITE_EXTERNAL_CODE, Constant.WRITE_EXTERNAL_PERMISSION);
        }

        // 本地视频截图
        String path = "/storage/emulated/0/DCIM/Camera/TG-2022-06-22-230432884.mp4";
        int frameCount = VideoUtil.getFrameCount(path);
        int firstFrame = 0;
        int SecondFrame = (int) (frameCount * (1f / 2));
        int thirdFrame = frameCount - 1;
        Bitmap bitmap1 = VideoUtil.getFrameFromIndex(path, firstFrame);
        imageView1.setImageBitmap(bitmap1);
        Bitmap bitmap2 = VideoUtil.getFrameFromIndex(path, SecondFrame);
        imageView2.setImageBitmap(bitmap2);
        Bitmap bitmap3 = VideoUtil.getFrameFromIndex(path, thirdFrame);
        imageView3.setImageBitmap(bitmap3);
    }
}